package top.deepdesigner.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import top.deepdesigner.pojo.DtsAddress;
import top.deepdesigner.service.DtsAddressService;

import java.util.List;

/**
 * Start up <br/>
 * Created with IntelliJ IDEA. <br/>
 * Project Name: shop_manage <br/>
 * Author: duanruiqing <br/>
 * DateTime: 2022/9/21 星期三 22:23:23 <br/>
 */
@Service
public class DtsAddressServiceImpl extends ServiceImpl<BaseMapper<DtsAddress>, DtsAddress> implements DtsAddressService {
  @Override
  public Long getAddressCount() {
    return this.count();
  }

  @Override
  public List<DtsAddress> getAddressList(Integer page, Integer limit, String sort, String order, String name, Integer userId) {
    QueryWrapper<DtsAddress> wrapper = new QueryWrapper<>();
    wrapper
        .like(!StringUtils.isEmpty(name), "name", name)
        .like(userId != null, "user_id", userId)
        .orderBy(true, "asc".equalsIgnoreCase(order), sort);
    Page<DtsAddress> userPage = new Page<>(page, limit);
    return this.page(userPage, wrapper).getRecords();
  }
}